import { useState, useCallback } from 'react'

export const useSwitch = () => {
  const [state, setState] = useState<boolean>(
    JSON.parse(localStorage.getItem('isImage') as string) === true
      ? true
      : false
  )
  document.documentElement.className = state ? '' : 'drak'
  const toggle = useCallback(() => {
    setState(!state)
    localStorage.setItem('isImage', JSON.stringify(!state))
  }, [state])

  return { toggle, state }
}
